package com.sicheng.蓝桥.练习题.dp.数位;

import java.util.ArrayList;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/1 19:05
 */
public class 不要62 {
    static int N = 9;
    static long[][] dp = new long[N][10];

    static void init() {
        for (int i = 0; i < 10; i++) {
            if (i != 4)
                dp[1][i] = 1;
        }

        for (int i = 2; i < N; i++) {
            for (int j = 0; j < 10; j++) {
                if (j == 4)
                    continue;
                for (int k = 0; k < 10; k++) {
                    if (k != 4 && j * 10 + k != 62)
                        dp[i][j] += dp[i - 1][k];
                }
            }
        }
    }


    static long dp(int n) {
        if (n == 0)
            return 1;
        long res = 0;
        long last = 0;
        ArrayList<Integer> nums = new ArrayList<>();
        while (n > 0) {
            nums.add(n % 10);
            n /= 10;
        }

        for (int i = nums.size() - 1; i >= 0; i--) {
            int x = nums.get(i);

            for (int j = 0; j < x; j++) {
                if (j == 4 || last * 10 + j == 62) {
                    continue;
                }
                res += dp[i + 1][j];
            }
            if (x == 4 || last * 10 + x == 62) {
                break;
            }

            last = x;

            if (i == 0)
                res++;
        }

        return res;
    }
}
